package com.G3.Global;

import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.math.Circle;

public class OverLapTester {    
    public static boolean overlapRectangles(Rectangle r1, Rectangle r2) {
        if(r1.x < r2.x + r2.width &&
           r1.x + r1.width > r2.x &&
           r1.y < r2.y + r2.height &&
           r1.y + r1.height > r2.y)
            return true;
        else
            return false;
    }           
    
    public static boolean pointInRectangle(Rectangle r, Vector2 p) {
        return r.x <= p.x && r.x + r.width >= p.x &&
               r.y <= p.y && r.y + r.height >= p.y;
    }
    
    public static boolean pointInRectangle(Rectangle r, float x, float y) {
        return r.x <= x && r.x + r.width >= x &&
               r.y <= y && r.y + r.height >= y;
    }
    
    public static boolean overlapCircles(Circle c1, Circle c2) {
        float distance = ((new Vector2(c1.x, c1.y)).sub(new Vector2(c2.x, c2.y))).len();
        float radiusSum = c1.radius + c2.radius;
        return distance <= radiusSum;
    }
    
    public static boolean pointInCircle(Circle c, Vector2 p) {
        return ((new Vector2(c.x, c.y)).sub(p)).len() < c.radius;
    }
}

